import java.util.Arrays; // sorting arrays in one line

public class Population {
	private Individual[] pop;
	private Selection selection;

	public Population(int size, Individual prototype, Selection selection) {
		this.selection = selection;
		pop = new Individual[size];
		for (int i = 0;i < size;i = i+1) {
			pop[i] = prototype.clone();
		}
	}

	public Individual getBest() {
		return pop[0];
	}

	public void nextGeneration() {
		int size = pop.length;
		Individual[] newPop = new Individual[size];
		for (int i = 0;i < size;i = i+1) {
			newPop[i] = selection.reproduce(pop);
		}
		Arrays.sort(newPop);
		pop = newPop;
	}
}
